CSharpTest.Net
WithDuplicateHandling Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > OrderedEnumeration<T> Class : WithDuplicateHandling Method

items
comparer
duplicateHandling

Glossary Item Box

Wraps an existing enumeration of Key/value pairs with an assertion about ascending order and handling for duplicate keys.

Syntax

Visual Basic (Declaration) 
Public Shared Function WithDuplicateHandling( _
   ByVal items As IEnumerable(Of T), _
   ByVal comparer As IComparer(Of T), _
   ByVal duplicateHandling As DuplicateHandling _
) As IEnumerable(Of T)
C# 
public static IEnumerable<T> WithDuplicateHandling( 
   IEnumerable<T> items,
   IComparer<T> comparer,
   DuplicateHandling duplicateHandling
)

Parameters

items
comparer
duplicateHandling

Example

Library/Library.Test/TestOrderedEnumeration.cs

C#Copy Code
char[] x = "aeiou".ToCharArray();
char[] y = "bcdfg".ToCharArray();
char[] z = "ez".ToCharArray();

var order = OrderedEnumeration<char>.Merge(x, y, z);
Assert.AreEqual("abcdeefgiouz", new string(new List<char>(order).ToArray()));

order = OrderedEnumeration<char>.Merge(Comparer<char>.Default, DuplicateHandling.LastValueWins, x, y, z);
Assert.AreEqual("abcdefgiouz", new string(new List<char>(order).ToArray()));

order = OrderedEnumeration<char>.Merge(Comparer<char>.Default, x, y);
order = OrderedEnumeration<char>.WithDuplicateHandling(order, Comparer<char>.Default,
                                                       DuplicateHandling.FirstValueWins);
Assert.AreEqual("abcdefgiou", new string(new List<char>(order).ToArray()));
VB.NETCopy Code
Dim x As Char() = "aeiou".ToCharArray()
Dim y As Char() = "bcdfg".ToCharArray()
Dim z As Char() = "ez".ToCharArray()

Dim order As var = OrderedEnumeration(Of Char).Merge(x, y, z)
Assert.AreEqual("abcdeefgiouz", New String(New List(Of Char)(order).ToArray()))

order = OrderedEnumeration(Of Char).Merge(Comparer(Of Char).[Default], DuplicateHandling.LastValueWins, x, y, z)
Assert.AreEqual("abcdefgiouz", New String(New List(Of Char)(order).ToArray()))

order = OrderedEnumeration(Of Char).Merge(Comparer(Of Char).[Default], x, y)
order = OrderedEnumeration(Of Char).WithDuplicateHandling(order, Comparer(Of Char).[Default], DuplicateHandling.FirstValueWins)
Assert.AreEqual("abcdefgiou", New String(New List(Of Char)(order).ToArray()))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys